package com.xinghai.web.controller.api;

import cn.dev33.satoken.stp.StpUtil;
import com.github.pagehelper.PageInfo;
import com.xinghai.common.constant.HttpStatus;
import com.xinghai.common.core.controller.BaseController;
import com.xinghai.common.core.domain.AjaxResult;
import com.xinghai.common.core.page.TableDataInfo;
import com.xinghai.common.utils.DataUtil;
import com.xinghai.common.utils.DateUtils;
import com.xinghai.common.utils.PageUtils;
import com.xinghai.common.utils.SecurityUtils;
import com.xinghai.system.domain.*;
import com.xinghai.system.domain.entity.*;
import com.xinghai.system.domain.vo.QdUserSendVO;
import com.xinghai.system.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static net.sf.jsqlparser.util.validation.metadata.NamedObject.user;

/**
 * 会员积分api接口
 *
 * @author xinghai
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/api/points")
public class QdPointsApiController extends BaseController
{
    @Autowired
    private IQdUserWalletService userWalletService;
    @Autowired
    private IQdUserPointsLogService userPointsLogService;


    /**
     * 查询积分额度
     */
    @GetMapping("/getPoints")
    public AjaxResult getPoints()
    {
        QdUserWallet w = userWalletService.getByUserId(StpUtil.getLoginId(""));
        return success(w.getPoints());
    }

    /**
     * 查询积分列表
     */
    @GetMapping("/getPointsList")
    public AjaxResult getPointsList(Integer pageNum, Integer pageSize)
    {
        QdUserPointsLog userPointsLog = new QdUserPointsLog();
        userPointsLog.setUserId(StpUtil.getLoginId(0L));
        PageUtils.startPage(pageNum,pageSize);
        PageUtils.orderBy("create_time desc");
        List<QdUserPointsLog> list = userPointsLogService.list(userPointsLog);
        return success(getDataTable(list));
    }

    /**
     * 充值积分
     */
    @PostMapping("/rechargePoints")
    public AjaxResult rechargePoints(@Validated @RequestBody RechargePointsDTO dto)
    {
        dto.setType("3");
        dto.setDetail("会员积分充值");
        return success(userWalletService.rechargePoints(dto));
    }

}
